<?php
/**
 * Author:   tangxiaowen
 * Email:    846506584@qq.com
 * Date:     2019/3/17 0017
 * Describe: 短信模板管理类
 */

namespace app\admin\controller\system;

use think\Controller;
use app\admin\controller\System;

class SmsTemplate extends Controller
{
    /**
     * 获取所有短信
     * @return array
     */
    public function getAllSms(){
        $allSmsData = cache('allSmsData');
        if(!$allSmsData){
            $allSmsData = db('sys_smstemplates')->select();

            //获取项名称 并替换掉短信模板中的签名
            $systemInfo = (new System())->getSystemInfo();
            //替换项目名称
            foreach($allSmsData as $k=>$v){
                $allSmsData[$k]['Content'] = str_replace('#sign#',$systemInfo['duanxinqianming'],$v['Content']);
            }
            cache('allSmsData',$allSmsData,1);
            $allSmsData = cache('allSmsData');
        }
        return $allSmsData;
    }

    /**
     * 根据短信名称获取短信信息
     * @param string $eName 短信名称
     * @return array
     */
    public function getSmsInfo($eName){

        $allSmsData = $this->getAllSms();
        $temp = [];
        foreach ($allSmsData as $k=>$v){
            if($v['EName'] == $eName){
                $temp = $v;
            }
        }
        return $temp;
    }

}